<template>
  <div class="exhibits-box">
    <div class="title_text" ref="titleText">
      <titles :title="props.info.text" />
      <div class="subTitle" v-if="props.info.subTitle">——{{ props.info.subTitle }}</div>
      <div
        class="content-text-heard-item"
        :class="{
          'content-text-heard-item0': store.styleInfo.themeColor == '#CFBDA8',
          'content-text-heard-item1': store.styleInfo.themeColor == '#8F9EBF',
          'content-text-heard-item2': store.styleInfo.themeColor == '#B9463F',
          'content-text-heard-item3': store.styleInfo.themeColor == '#343029',
          'content-text-heard-item4': store.styleInfo.themeColor == '#171719',
        }"
      >
        <!-- <textMax :data="props.info.remarks" :maxLen="101" :tip="''" /> -->
        <van-text-ellipsis
          :content="getTrimText(props.info.remarks)"
          :rows="3"
          expand-text="展开"
          collapse-text="收起"
        />
      </div>
    </div>
    <div>
      <div
        ref="exhibitsRightImageList"
        class="exhibitsRightImage"
        :class="{ exhibitsRightImage2: props.tabDatas.length > 2 }"
      >
        <div
          v-for="item in props.tabDatas"
          :key="item.id"
          class="exhibitsRightImageBox"
          @click="pathInfo(item.id)"
          ref="exhibitsRightImageBox"
        >
          <div class="item-left-img-box">
            <t-image
              fit="cover"
              class="item-left-img"
              :src="$filters.getLinkUrl(item.coverUrl, '?imageView2/0/h/158/format/webp')"
              alt=""
            />
            <!-- <div class="shadow"></div> -->
          </div>
          <div class="item-heard">
            <div>
              <span class="titleText" :style="{}"> {{ item.name }}</span>
              <!-- <div class="line"></div> -->
            </div>
          </div>
        </div>
      </div>
    </div>
    <div
      @click="pathChild"
      :style="{
        fontFamily: 'SourceHanSerifCN-Bold',
        color: '#fff',
      }"
      class="left-btn flex-c-c-c"
    >
      <div class="btn-img">
        <buttonIcon />
      </div>
      <span>查看全部</span>
    </div>
  </div>
</template>

<script setup lang="ts">
// @ts-nocheck
import { pathList, pathListLoop } from '../route';
import { onMounted, ref } from 'vue';
import { urls } from '@/utils/request/upload';
import titles from '@/wap/wapPage/wapComponents/title/title.vue';
import buttonIcon from '@/wap/wapPage/wapComponents/title/buttonIcon.vue';
import { useProjectStore } from '@/store';
import { useRoute, useRouter } from 'vue-router';
import textMax from '@/components/textMax/textMax.vue';
import arrowLeft from '../publicComponents/wapComponents/arrowLeft.vue';
import arrowRight from '../publicComponents/wapComponents/arrowRight.vue';
import UnitImageNull from '@/components/unitImageNull/unitImageNull.vue';
import { handlemouse, getTrimText } from '@/utils/minxin';
import { imgEnter, imgLeave } from '@/pages/templatePage/components/Subunit/component/hover';
const router = useRouter();
const route = useRoute();
const store = useProjectStore();
const props = defineProps({
  info: {
    type: Object,
  },
  tabDatas: {
    type: Array,
  },
});

const exhibitsRightImage = ref(null);
const exhibitsRightImageBox = ref(null);
const titleText = ref(null);
const arrowBox = ref(null);
const exhibitsRightImageList = ref(null);
const arrowBox2 = ref(null);
const current = ref(0);
const pathInfo = (e: number) => {
  router.push({
    name: route.meta.loopType ? pathListLoop[2] : pathList[2],
    query: { id: e, moduleId: props.info.id },
  });
};
const addCruuent = (num: number) => {
  if (current.value === 0 && num < 0) {
    return;
  } else if (current.value === props.tabDatas.length - 3 && num > 0) {
    return;
  } else {
    current.value = current.value + num;
    exhibitsRightImage.value.style.transform = `translateX(${-400 * current.value}px)`;
  }
};
onMounted(() => {
  // hover('.titleText', '.line', '.exhibitsRightImageBox', props.tabDatas.length);

  const observer = new IntersectionObserver((entries) => {
    let canTrigger = true; // 标记是否可以触发
    entries.forEach((entry) => {
      if (entry.isIntersecting && canTrigger) {
        // 当元素进入视窗口时触发的代码
        titleText.value.classList.add('animation-box');

        // 设置一个延迟时间，防止频繁触发
        canTrigger = false;
        setTimeout(() => {
          canTrigger = true;
        }, 500); // 设置延迟时间为 500 毫秒
      } else {
        // if (titleText.value) {
        //   titleText.value.classList.remove('animation-box');
        // }
      }
    });
  });
  observer.observe(titleText.value);
  const observer1 = new IntersectionObserver((entries) => {
    let canTrigger1 = true; // 标记是否可以触发
    entries.forEach((entry) => {
      if (entry.isIntersecting && canTrigger1) {
        // console.log('exhibitsRightImageBox', exhibitsRightImageBox.value.length);
        for (let index = 0; index < exhibitsRightImageBox.value.length; index++) {
          setTimeout(() => {
            exhibitsRightImageBox.value[index].classList.add('animation-box2');
          }, 300 * index);
        }
        if (arrowBox.value) {
          setTimeout(() => {
            arrowBox.value.classList.add('animation-box2');
            arrowBox2.value.classList.add('animation-box2');
          }, exhibitsRightImageBox.value.length * 300);
        }
        // 设置一个延迟时间，防止频繁触发
        canTrigger1 = false;
        setTimeout(() => {
          canTrigger1 = true;
        }, 500); // 设置延迟时间为 500 毫秒
      } else {
        // if (exhibitsRightImageBox.value) {
        //   for (let i = 0; i < exhibitsRightImageBox.value.length; i++) {
        //     exhibitsRightImageBox.value[i].classList.remove('animation-box2');
        //   }
        // }
        // if (arrowBox.value) {
        //   arrowBox.value.classList.remove('animation-box2');
        //   arrowBox2.value.classList.remove('animation-box2');
        // }
      }
    });
  });
  observer1.observe(exhibitsRightImageList.value);
});
const pathChild = () => {
  store.setchildModel(props.info);
  store.setCurrent(0);
  router.push({
    name: route.meta.loopType ? pathListLoop[8] : pathList[8],
    query: { childId: props.info.id },
  });
};
</script>

<style lang="less" scoped>
@import './index.less';
.exhibits-box {
  // display: flex;
  // overflow: hidden;
  position: relative;
  // background: #fbf9f6;
  padding: 24px 0;
  .title_text {
    width: 100%;
    // height: 170px;
    margin: auto;
  }
  .left-btn {
    margin: auto;
    margin-top: 16px;
  }
  .exhibitsRightImage2 {
    justify-content: start !important;
    padding-left: 16px;
    padding-right: 16px;
    .exhibitsRightImageBox {
    }
  }

  .exhibitsRightImage {
    display: flex;
    transition: all 0.5s;
    justify-content: center;
    align-items: center;
    margin-top: 12px;
    overflow: auto;
    > div {
      margin-right: 10px;
    }
    > div:last-child {
      margin-right: 0;
    }
  }
  .exhibitsRightImageBox {
    transition: all 0.5s;
    opacity: 0;
    width: 158px;
    flex-shrink: 0;
  }
  .exhibitsRightImage::-webkit-scrollbar {
    display: none;
  }
  .item-heard {
    width: 100%;
    height: 36px;
    // padding: 24px 50px;
    text-align: center;
    background: #fff;
    box-shadow: 0px 1px 2px 0px rgba(0, 0, 0, 0.05);
    font-size: 15px !important;
    line-height: 36px;
    padding: 0 8px;
    > div {
      width: 100%;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;

      // height: 30px;
      // line-height: 28px;
      font-family: SourceHanSerifCN-Bold, SourceHanSerifCN;
    }
  }
}
.arrow-box-right {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  /deep/.iconfonts {
    color: #fff !important;
  }
}
.arrowBox2,
.arrowBox1 {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  position: absolute;
  top: 212px;

  z-index: 101;
  opacity: 0;
  transition: all 0.5s;
  > div {
    width: 32px;
    height: 32px;
    border-radius: 50%;
  }
  /deep/.iconfonts {
    color: #fff !important;
  }
}
.arrowBox2 {
  right: -16px;
}
.arrowBox1 {
  left: -16px;
}
// .arrowBoxRight{
//   width: 32px;
//   height: 32px;
//   // opacity: 0;
// }
.line {
  width: 0px;
  height: 2px;
  background: #000;
  transform: all 0.5s;
  margin-bottom: 15px;
  margin: auto;
}

.shadow {
  width: 158px;
  height: 158px;
  position: absolute;
  top: 0;
  background: rgba(0, 0, 0, 0);
  transition: all 0.5s;
  z-index: 99;
}
.item-left-img-box {
  width: 100%;
  height: 158px;
  overflow: hidden;
  transition: all 0.5s;
  position: relative;
  .t-image__wrapper {
    width: 100%;
    height: 100%;
    transition: all 0.5s;
  }
}
// .item-left-img-box:hover .shadow {
//   background: rgba(0, 0, 0, 0.4);
// }
// .item-left-img-box:hover .t-image__wrapper {
//   transform: scale(1.1);
// }
.animation-box {
  animation: slideIn 0.5s forwards;
}
@keyframes slideIn {
  0% {
    padding-top: 194px;
    // transform: translateY(100%); /* 元素初始位置 */
    opacity: 0;
  }
  100% {
    padding-top: 0;
    opacity: 1;
    // transform: translateY(0); /* 元素最终位置 */
  }
}
.animation-box2 {
  animation: slideIn2 1s forwards;
}
@keyframes slideIn2 {
  0% {
    // padding-right: 980px;
    transform: translateX(-10%); /* 元素初始位置 */
    opacity: 0;
  }
  100% {
    opacity: 1;
    transform: translateX(0); /* 元素最终位置 */
  }
}
.content-text-heard-item0 {
  :deep(.van-text-ellipsis__action) {
    color: #d2ad77;
  }
}
.content-text-heard-item1 {
  :deep(.van-text-ellipsis__action) {
    color: #133889;
  }
}
.content-text-heard-item2 {
  :deep(.van-text-ellipsis__action) {
    color: #ab1d22;
  }
}
.content-text-heard-item3 {
  :deep(.van-text-ellipsis__action) {
    color: #3f4d4f;
  }
}
.content-text-heard-item4 {
  :deep(.van-text-ellipsis__action) {
    color: #949494;
  }
}
.content-text-heard-item {
  padding: 0 16px;
  margin-top: 10px;
}
.subTitle {
  padding: 0 16px;
  padding-top: 6px;
}
</style>
